#Import Necessary Modules
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
import seaborn as sns
import warnings
import arabic_reshaper
from bidi.algorithm import get_display
import math
import plotly.express as px
warnings.filterwarnings('ignore')
def _(text):
return get_display(arabic_reshaper.reshape(u'%s' % str(text)))
#Import Data
apps = pd.read_csv('dataset\\CafeBazaar-final.csv', encoding='utf-8')
# How many apps do we have per each subject? We should consider 'Kind' column.
app_type_count = apps.Kind.value_counts().sort_values(ascending = False)
fig = px.pie(apps, values=app_type_count.values, names=app_type_count.index,
title = 'تعداد برنامه ها و بازی های موجود در مجموعه داده',
color_discrete_sequence=px.colors.qualitative.Antique,
)
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="green",
legend_title_font_family="B Titr",
title_x=0.5
)
fig.update_traces(textposition='inside', textinfo='value+percent', textfont_size=20)
fig.show()
#Let's discriminate applications and games
applications = apps[apps['Kind'] == 'برنامه']
games = apps[apps['Kind'] == 'بازی']
# APPLICATIONS Category Distribution
num_apps_in_category_applications = applications['Category'].value_counts().sort_values(ascending = False)
import plotly.express as px
fig = px.bar(apps, x = num_apps_in_category_applications.index, y = num_apps_in_category_applications.values,
color = num_apps_in_category_applications,
color_continuous_scale=px.colors.cyclical.mygbm,
title = 'توزیع تعداد اپلیکیشن های کاربردی در دسته بندی های مختلف مارکت کافه بازار')
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="purple",
legend_title_font_family="B Titr",
xaxis_title="دسته بندی برنامه ها",
yaxis_title="تعداد",
title_x=0.5
)
fig.update_xaxes(title_font_family="B Titr", tickangle=-45)
fig.show()
# GAMES Category Distribution
num_apps_in_category_games = games['Category'].value_counts().sort_values(ascending = False)
num_apps_in_category_applications = applications['Category'].value_counts().sort_values(ascending = False)
import plotly.express as px
fig = px.bar(apps, x = num_apps_in_category_games.index, y = num_apps_in_category_games.values,
color = num_apps_in_category_games,
color_continuous_scale=px.colors.cyclical.Phase,
title = 'توزیع تعداد اپلیکیشن های بازی در دسته بندی های مختلف مارکت کافه بازار')
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="purple",
legend_title_font_family="B Titr",
xaxis_title="دسته بندی بازی ها",
yaxis_title="تعداد",
title_x=0.5
)
fig.update_xaxes(title_font_family="B Titr", tickangle=-45)
fig.show()
application_type_count = applications.Type.value_counts().sort_values(ascending = False)
game_type_count = games.Type.value_counts().sort_values(ascending = False)
import plotly.graph_objects as go
from plotly.subplots import make_subplots
# Create subplots: use 'domain' type for Pie subplot
fig = make_subplots(rows=1, cols=2, specs=[[{'type':'domain'}, {'type':'domain'}]])
fig.add_trace(go.Pie(labels = application_type_count.index, values = application_type_count.values),
1, 1)
fig.add_trace(go.Pie(labels = game_type_count.index, values = game_type_count.values),
1, 2)
colors = ['lightgreen','gold', 'mediumturquoise']
fig.update_traces(hole=.3, hoverinfo="label+percent+name",
marker=dict(colors=colors, line=dict(color='#000000', width=2)))
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="Purple",
legend_title_font_family="B Titr",
title='توزیع اپلیکیشن ها بر اساس نوع پرداخت',
title_x=0.5,
annotations=[dict(text='برنامه ها', x=0.18, y=0.5, font_size=20, showarrow=False),
dict(text='بازی ها', x=0.82, y=0.5, font_size=20, showarrow=False)]
)
fig.show()
# Visualize the Rating of APPLICATIONS. We should filter out those apps that don't have any reviews.
apprev = applications[applications.Reviews > 0]
fig = px.histogram(apprev, x='Rating',
title='هیستوگرام امتیاز برنامه ها در کافه بازار',
marginal='box',
labels={'x':'امتیازها', 'y':'تعداد'},
color = 'Type',
color_discrete_sequence=px.colors.qualitative.Pastel,
)
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="purple",
legend_title_font_family="B Titr",
xaxis_title="امتیاز برنامه ها",
yaxis_title="تعداد",
title_x=0.5,
barmode='overlay'
)
fig.show()
# Same as above, instead this time for GAMES
gamerev = games[games.Reviews > 0]
fig = px.histogram(gamerev, x='Rating',
title='هیستوگرام امتیاز بازی ها در کافه بازار',
marginal='box',
labels={'x':'امتیازها', 'y':'تعداد'},
color = 'Type',
color_discrete_sequence=px.colors.qualitative.Dark24,
)
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="purple",
legend_title_font_family="B Titr",
xaxis_title="امتیاز بازی ها",
yaxis_title="تعداد",
title_x=0.5,
barmode='overlay'
)
fig.show()
#Let's plot kde for reviews
fig, axes = plt.subplots(1, 2, figsize=(20,10))
fig.suptitle(_('توزیع امتیازها در برنامه های کاربردی و بازی ها'), fontsize=20)
sns.set_context("paper", rc={"font.size":20,"axes.titlesize":15,"axes.labelsize":25})
matplotlib.rcParams['font.family'] = 'B Titr'
sns.set(font="B Titr")
sns.distplot(ax=axes[0], a=apprev['Rating'].values, kde=True, bins=50, color='purple', axlabel=_('امتیاز برنامه ها'))
axes[0].legend(["($\mu=${0:.2g}, $\sigma=${1:.2f})".format(np.average(applications['Rating'].values),
np.std(applications['Rating'].values))], fontsize='x-large', title_fontsize='40')
sns.distplot(ax=axes[1], a=gamerev['Rating'].values, kde=True, bins=50, color='mediumturquoise', axlabel=_('امتیاز بازی ها'))
axes[1].legend(["($\mu=${0:.2g}, $\sigma=${1:.2f})".format(np.average(games['Rating'].values),
np.std(games['Rating'].values))], fontsize='x-large', title_fontsize='40')
axes[0].set(ylabel = _('چگالی احتمال'))
axes[1].set(ylabel = _('چگالی احتمال'))
axes[0].tick_params(labelsize=20)
axes[1].tick_params(labelsize=20)
plt.figure();
<Figure size 432x288 with 0 Axes>
#Visualize Box-Plot for each APPLICATIONS category based on their ratings
plt.figure(figsize=(30,20))
fig = px.box(applications, x='Category', y='Rating', title = 'نمودار جعبه ای امتیاز به تفکیک دسته بندی برنامه ها',
color = 'Category',
color_discrete_sequence=px.colors.qualitative.Set2,
)
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="purple",
legend_title_font_family="B Titr",
xaxis_title="دسته بندی برنامه ها",
yaxis_title="امتیاز",
title_x=0.5
)
fig.update_xaxes(title_font_family="B Titr", tickangle=-45)
fig.show();
<Figure size 2160x1440 with 0 Axes>
#Same as above for GAMES
plt.figure(figsize=(30,20))
fig = px.box(games, x='Category', y='Rating', title = 'نمودار جعبه ای امتیاز به تفکیک دسته بندی بازی ها',
color = 'Category',
color_discrete_sequence=px.colors.qualitative.Set2,
)
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="purple",
legend_title_font_family="B Titr",
xaxis_title="دسته بندی بازی ها",
yaxis_title="امتیاز",
title_x=0.5
)
fig.update_xaxes(title_font_family="B Titr")
fig.show();
<Figure size 2160x1440 with 0 Axes>
# We want to know which category installed most?
import plotly.graph_objects as go
from plotly.subplots import make_subplots
dfapp = applications.groupby(['Category'])['InstallsNum'].sum().sort_values(ascending = False).reset_index()
dfgame = games.groupby(['Category'])['InstallsNum'].sum().sort_values(ascending = False).reset_index()
category_app = list(dfapp.Category)
installs_app = list(dfapp.InstallsNum)
category_game = list(dfgame.Category)
installs_game = list(dfgame.InstallsNum)
fig = make_subplots(
cols = 2, rows = 1,
column_widths = [0.4, 0.4],
subplot_titles = ('دسته بندی بر اساس تعداد نصب: <b>برنامه ها<br /> <br />', 'دسته بندی بر اساس تعداد نصب: <b>بازی ها<br /> <br />'),
specs = [[{'type': 'treemap', 'rowspan': 1}, {'type': 'treemap'}]]
)
fig.add_trace(go.Treemap(
labels = category_app,
parents=[""]*len(category_app),
values = installs_app,
textinfo = "label",
textposition = 'middle center',
marker=dict(colorscale='sunsetdark_r')
),
row = 1, col = 1)
fig.add_trace(go.Treemap(
labels = category_game,
parents=[""]*len(category_game),
values = installs_game,
textinfo = "label",
textposition = 'middle center',
marker=dict(colorscale='sunsetdark_r'),
),
row = 1, col = 2)
fig.update_layout(
autosize=False,
width= 1000,
height=1000,
font_family="B Titr",
font_size=30,
title_font_family="B Titr",
title_font_color="Purple",
legend_title_font_family="B Titr",
title_x=0.5,
)
fig.show()
# Which games have the most fans? List 10 top of them.
gametop = games.groupby('App')[['InstallsNum']].sum().reset_index().sort_values('InstallsNum', ascending=False).head(10)
plt.figure(figsize=(50,30))
fig = px.bar(gametop, x = 'App', y = 'InstallsNum',
color = 'App',
color_continuous_scale=px.colors.cyclical.mygbm,
title = 'پرطرفدارترین بازی ها از نظر تعداد نصب')
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="purple",
legend_title_font_family="B Titr",
xaxis_title="بازی ها",
yaxis_title="میزان نصب",
title_x=0.5,
showlegend = False
)
fig.update_xaxes(title_font_family="B Titr", tickangle=45)
fig.show()
<Figure size 3600x2160 with 0 Axes>
# Which APPLICATIONS have been more profitable? We can consider just paid ones.
apptop = applications.groupby('App')[['SellAmount']].sum().reset_index().sort_values('SellAmount', ascending=False).head(10)
plt.figure(figsize=(50,30))
fig = px.bar(apptop, x = 'App', y = 'SellAmount',
color = 'App',
color_continuous_scale=px.colors.cyclical.Phase_r,
title = 'پرفروش ترین برنامه ها در کافه بازار')
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="purple",
legend_title_font_family="B Titr",
xaxis_title="برنامه ها",
yaxis_title="حداقل میزان فروش به تومان",
title_x=0.5,
showlegend = False
)
fig.update_xaxes(title_font_family="B Titr", tickangle=-45)
fig.show()
<Figure size 3600x2160 with 0 Axes>
#Same as above for GAMES
gametop = games.groupby('App')[['SellAmount']].sum().reset_index().sort_values('SellAmount', ascending=False).head(10)
plt.figure(figsize=(50,30))
fig = px.bar(gametop, x = 'App', y = 'SellAmount',
color = 'App',
color_continuous_scale=px.colors.cyclical.mygbm,
title = 'پرفروش ترین بازی ها در کافه بازار')
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="purple",
legend_title_font_family="B Titr",
xaxis_title="بازی ها",
yaxis_title="حداقل میزان فروش به تومان",
title_x=0.5,
showlegend = False
)
fig.update_xaxes(title_font_family="B Titr", tickangle=-45)
fig.show()
<Figure size 3600x2160 with 0 Axes>
# Which developer has released the most apps in this market?
devtop = apps.Developer.value_counts().sort_values(ascending=False).head(15)
plt.figure(figsize=(50,30))
fig = px.bar(devtop, x = devtop.index, y = devtop.values,
color = devtop,
color_continuous_scale=px.colors.sequential.Sunsetdark,
title = 'پرکارترین توسعه دهنده ها')
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="purple",
legend_title_font_family="B Titr",
xaxis_title="توسعه دهنده",
yaxis_title="تعداد اپلیکیشن های منتشرشده",
title_x=0.5,
showlegend = False
)
fig.update_xaxes(title_font_family="B Titr", tickangle=-45)
fig.show()
<Figure size 3600x2160 with 0 Axes>
# Which APPLICATIONS received the most number of reviews?
most_no_of_reviews_app = applications.groupby('App')[['Reviews']].sum().reset_index().sort_values('Reviews', ascending=False).head(10)
plt.figure(figsize=(50,30))
fig = px.bar(most_no_of_reviews_app, x = 'App', y = 'Reviews',
color = 'Reviews',
color_continuous_scale=px.colors.cyclical.Phase,
title = 'بیشترین ثبت امتیاز روی برنامه ها')
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="purple",
legend_title_font_family="B Titr",
xaxis_title="نام برنامه",
yaxis_title="تعداد امتیازات داده شده روی برنامه",
title_x=0.5,
showlegend = False
)
fig.update_xaxes(title_font_family="B Titr", tickangle=-45)
fig.show()
<Figure size 3600x2160 with 0 Axes>
# Same as above for GAMES
most_no_of_reviews_game = games.groupby('App')[['Reviews']].sum().reset_index().sort_values('Reviews', ascending=False).head(10)
plt.figure(figsize=(50,30))
fig = px.bar(most_no_of_reviews_game, x = 'App', y = 'Reviews',
color = 'Reviews',
color_continuous_scale=px.colors.cyclical.Phase,
title = 'بیشترین ثبت امتیاز روی بازی ها')
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="purple",
legend_title_font_family="B Titr",
xaxis_title="نام بازی",
yaxis_title="تعداد امتیازات داده شده روی بازی",
title_x=0.5,
showlegend = False
)
fig.update_xaxes(title_font_family="B Titr", tickangle=-45)
fig.show()
<Figure size 3600x2160 with 0 Axes>
# Do we have any linear relationship between features?
plt.figure(figsize=(16,8))
corr = apps.corr()
matplotlib.rcParams['font.family'] = 'Tahoma'
sns.set(font="Tahoma")
sns.heatmap(corr, annot=True, linewidths=.5)
plt.show()
#sns.set_theme(style="ticks")
paid_apps = apprev[apprev['Type'] == 'پولی']
paid_games = gamerev[gamerev['Type'] == 'پولی']
g = sns.jointplot(x='Price', y='Rating', color="#4CB391", data=paid_apps)
plt.figure();
<Figure size 432x288 with 0 Axes>
sns.jointplot(x='Price', y='Rating', color="#ff039a", data=paid_games)
<seaborn.axisgrid.JointGrid at 0x2154f191760>
sns.jointplot(x='Price', y='InstallsNum', color="#0799a3", data=paid_apps)
<seaborn.axisgrid.JointGrid at 0x21551bad760>
sns.jointplot(x='Price', y='InstallsNum', color="#fca205", data=paid_games)
<seaborn.axisgrid.JointGrid at 0x2154f024340>
# Due to the high dispersion of data, we categorize some of them.
Price_Cat_applications = pd.cut(applications.Price, bins=[0,5000, 10000, 15000, 20000, 25000, 30000, 35000, 40000],
labels=['0-5000','5001-10000','10001-15000','15001-20000', '20001-25000', '25001-30000', '30001-35000', '35001-40000'])
applications.insert(9,'PriceGroup',Price_Cat_applications)
Price_Cat_games = pd.cut(games.Price, bins=[0,5000, 10000, 15000, 20000, 25000, 30000, 35000, 40000],
labels=['0-5000','5001-10000','10001-15000','15001-20000', '20001-25000', '25001-30000', '30001-35000', '35001-40000'])
games.insert(9,'PriceGroup',Price_Cat_games)
# Now we can clearly see which price group have the most APPLICATIONS
pricegroupapp = applications.PriceGroup.value_counts()
plt.figure(figsize=(50,30))
fig = px.bar(pricegroupapp, x = pricegroupapp.index, y = pricegroupapp.values,
color = pricegroupapp,
color_continuous_scale=px.colors.qualitative.D3_r,
title = 'دسته بندی برنامه ها در گروه های مختلف قیمتی')
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="purple",
legend_title_font_family="B Titr",
xaxis_title="گروه قیمت برنامه ها",
yaxis_title="تعداد",
title_x=0.5,
showlegend = True
)
fig.update_xaxes(title_font_family="B Titr")
fig.show()
<Figure size 3600x2160 with 0 Axes>
#Same as above for GAMES
pricegroupgames = games.PriceGroup.value_counts().sort_values(ascending=False)
plt.figure(figsize=(50,30))
fig = px.bar(pricegroupgames, x = pricegroupgames.index, y = pricegroupgames.values,
color = pricegroupgames,
color_continuous_scale=px.colors.qualitative.D3_r,
title = 'دسته بندی بازی ها در گروه های مختلف قیمتی')
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="purple",
legend_title_font_family="B Titr",
xaxis_title="گروه قیمت بازی ها",
yaxis_title="تعداد",
title_x=0.5,
showlegend = True
)
fig.update_xaxes(title_font_family="B Titr")
fig.show()
<Figure size 3600x2160 with 0 Axes>
Size_Cat_apps = pd.cut(applications.Size, bins=[0,10,20,30,40,50,60,70,80,1000],
labels=['0-10', '10-20', '20-30', '30-40', '40-50', '50-60', '60-70', '70-80', ' > 80'])
applications.insert(9,'SizeGroup',Size_Cat_apps)
Size_Cat_games = pd.cut(games.Size, bins=[0,10,20,30,40,50,60,70,80,1000],
labels=['0-10', '10-20', '20-30', '30-40', '40-50', '50-60', '60-70', '70-80', ' > 80'])
games.insert(9,'SizeGroup',Size_Cat_games)
# Counting the number of APPLICATIONS based on their size group
SizeGroupCountApps = applications.SizeGroup.value_counts()
fig = px.pie(SizeGroupCountApps, values = SizeGroupCountApps.values, names = SizeGroupCountApps.index,
title = 'شمارس تعداد برنامه ها بر اساس گروه حجمی به مگابایت',
color_discrete_sequence=px.colors.qualitative.Set2,
)
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="green",
legend_title_font_family="B Titr",
title_x=0.5
)
fig.update_traces(textposition='inside', textinfo='percent', textfont_size=20)
fig.show()
# Same as above for GAMES
SizeGroupCountGames = games.SizeGroup.value_counts()
fig = px.pie(SizeGroupCountGames, values = SizeGroupCountGames.values, names = SizeGroupCountGames.index,
title = 'شمارس تعداد بازی ها بر اساس گروه حجمی به مگابایت',
color_discrete_sequence=px.colors.qualitative.Pastel,
)
fig.update_layout(
font_family="B Titr",
title_font_family="B Titr",
title_font_color="green",
legend_title_font_family="B Titr",
title_x=0.5
)
fig.update_traces(textposition='inside', textinfo='percent', textfont_size=20)
fig.show()
# Just think that waffle chart give me a better sense to understand in which price group are the most APPLICATIONS released?
from pywaffle import Waffle
sns.set_context("notebook")
matplotlib.rcParams['font.family'] = 'B Titr'
sns.set(font="B Titr")
fig = plt.figure(
FigureClass = Waffle,
rows=10,
columns = 24,
figsize = (20, 10),
values=pricegroupapp.values,
labels= list(pricegroupapp.index),
legend={'loc': 'best', 'bbox_to_anchor': (1.1, 1), 'fontsize':12},
starting_location='NW'
)
fig.set_facecolor('#EEEEEE')
plt.title(_('توزیع تعداد نصب برنامه ها در گروه های مختلف'), size = 20)
plt.show()
from pywaffle import Waffle
sns.set_context("notebook")
fig = plt.figure(
FigureClass = Waffle,
rows=10,
columns = 24,
figsize = (20, 10),
values=pricegroupgames.values,
labels= list(pricegroupgames.index),
legend={'loc': 'best', 'bbox_to_anchor': (1.1, 1), 'fontsize':12},
starting_location='NW'
)
fig.set_facecolor('#EEEEEE')
plt.title(_('توزیع تعداد نصب بازی ها در گروه های مختلف'), size = 20)
plt.show()